package com.cc8w.admin.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.cc8w.entity.UserPojo;
import com.cc8w.service.UserService;

@Controller
@RequestMapping("/admin/welcome")
public class WelcomeAdmin extends AdminBaseController {
	@Autowired
    private UserService userService;

	/*
	 * 1.第一种返回view层数据的方式,网页显示
	 */
    @RequestMapping("/index")
    public ModelAndView index()
    {
        System.out.println("index.dodo");
        
        
        
        ModelAndView mav = new ModelAndView("admin/welcome/index");
        mav.addObject("hi", "467 th");
        return mav;
    }
    
    /**
     * 测试一下用通用方法接收传递的参数
     * 2.第二种返回view层数据的方式,网页显示
     */
    @RequestMapping("/testreq")
    public String testReq(HttpServletRequest request,Model model) {
    	//int userId = Integer.parseInt(request.getParameter("id"));
        
    	
    	//本来是实例化Service,但是现在把Service交给了Spring管理,直接获取即可
    	UserPojo user = this.userService.queryUserOne();
        
        model.addAttribute("user", user);
        return "admin/welcome/showuser";
    }
    
    /**
     * 3.第二种返回view层数据的方式,返回json
     */
    
    @RequestMapping("/testreq2")
    @ResponseBody
    public List<UserPojo> testreq2(HttpServletRequest request,Model model)
    {
        System.out.println("index.dodo");   
    	ArrayList <UserPojo> uplist = new ArrayList<UserPojo>();
    	uplist.add(new UserPojo(1,"aaa",1));
    	uplist.add(new UserPojo(2,"bbb",2));
    	uplist.add(new UserPojo(3,"ccc",2));
    	uplist.add(new UserPojo(4,"ddd",1));
    	uplist.add(new UserPojo(5,"eee",1));
    	return uplist;
    }
    
    
    
}
